/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = __frct_stat_system_update.c                                */
/*  NOTE      =                                                    */
/*  DATE      = 2016/04/18 by geyh                                 */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "module_comm.h"
#include "module.h"
#include "conntrack.h"

#include "frproto_detect.h"
#include "apmtest_cunit.h"


static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}


int __frct_stat_system_update(Conntrack *p_st_ct
        , int i_syn
        , int i_established
        , int i_disconnect
        , int i_destroy);

static void case1(void)
{
    Conntrack *p_st_ct = NULL;
    int i_ret = 0;
    
    i_ret = __frct_stat_system_update(p_st_ct,0,0,0,0);

    CU_ASSERT_EQUAL(i_ret,FR_FAIL);
    
    return;
}

static void case2(void)
{
    Conntrack *p_st_ct = NULL;
    int i_ret = 0;

    p_st_ct = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_ct, 0x00, sizeof(Conntrack));

    i_ret = __frct_stat_system_update(p_st_ct,0,0,0,0);

    CU_ASSERT_EQUAL(i_ret,FR_FAIL);

    frfree(p_st_ct);
    return;
}


static void case3(void)
{
    Conntrack *p_st_ct = NULL;
    int i_ret = 0;
    L7_analyzer *p_st_l7_analyzer = NULL;
    L7_module *p_st_l7_module = NULL;

    p_st_ct = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_ct, 0x00, sizeof(Conntrack));

    p_st_l7_module = (L7_module *)frmalloc(sizeof(L7_module));
    memset(p_st_l7_module, 0x00, sizeof(L7_module));
//    p_st_l7_module = (L7_module *)frmalloc(sizeof(L7_module));

    p_st_l7_analyzer = &p_st_ct->st_l7_analyzer;
    p_st_l7_analyzer->p_st_l7_module = p_st_l7_module;

    i_ret = __frct_stat_system_update(p_st_ct,0,0,0,0);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);

    frfree(p_st_ct);
    frfree(p_st_l7_module);
    return;
}

int add_suite()
{
    CU_pSuite pSuite = NULL;

    pSuite = CU_add_suite("__frct_stat_system_update 测试", __suite_init, __suite_cleanup);

    if (NULL == pSuite)
    {
        return 1;
    }


    //增加测试用例
    CU_add_test(pSuite, "case1", case1);
    CU_add_test(pSuite, "case2", case2);
    CU_add_test(pSuite, "case3", case3);


    return 0;

}

int main(int argc, char **argv)
{
    fr_slab_init(52428800, "test");
    run_cunit(add_suite);
    fr_slab_destroy();
    return 0;
}